﻿@namespace Masa.Scheduler.Web.Admin.Components.Tsc
@inherits TscComponentBase

@if (Search != null)
{
    <div class="d-flex pt-2 @(IsService?"mb-4":"")">
        <SAutoComplete Label="@I18n.Apm("Search.Environment")"
                       Items="environments"
                       TItem="string"
                       TValue="string"
                       TItemValue="string"
                       ItemText="item=>item"
                       ItemValue="item=>item"
                       Style="max-width:130px"
                       Class="rounded-2 mr-1"
                       Disabled="isEnvLoading"
                       Loading="isEnvLoading"
                       Small
                       HideSelected=false
                       BackgroundColor="white"
                       Value=Search.Environment
                       ValueChanged="OnEnvironmentChanged" />

        <SAutoComplete Value=Search.Project
                       ValueChanged="OnProjectChanged"
                       Items="projects"
                       TItem="string"
                       TValue="string"
                       TItemValue="string"
                       ItemText="item=>item"
                       ItemValue="item=>item"
                       Disabled="isServiceLoading"
                       Small
                       HideSelected=false
                       Label="@I18n.Apm("Search.Project")"
                       BackgroundColor="white"
                       Loading="isServiceLoading"
                       Clearable
                       Class="rounded-2 mr-1"
                       Style="max-width:200px" />

        <SAutoComplete Label="@I18n.Apm("Search.ServiceType")"
                       Clearable
                       Items="types"
                       TItem="string"
                       TValue="string"
                       TItemValue="string"
                       ItemText="item=>item"
                       ItemValue="item=>item"
                       Style="max-width:130px"
                       Class="rounded-2 mr-1"
                       Disabled="isEnvLoading"
                       Loading="isEnvLoading"
                       Small
                       HideSelected=false
                       BackgroundColor="white"
                       ValueChanged="ServiceTypeChanged"
                       Value=Search.ServiceType />

        <SAutoComplete Value=Search.Service
                       ValueChanged="OnServiceChanged"
                       Items="services"
                       TItem="ValueTuple<string,string>"
                       TValue="string"
                       TItemValue="string"
                       ItemText="item=>item.Item1"
                       ItemValue="item=>item.Item1"
                       Disabled="isServiceLoading"
                       Small
                       HideSelected=false
                       Label="@I18n.Apm("Search.Service")"
                       BackgroundColor="white"
                       Loading="isServiceLoading"
                       Clearable
                       Class="rounded-2 mr-1"
                       Style="max-width:200px">
            <ItemContent>
                <div class="d-flex justify-space-between m-list-item__title">
                    <div>@context.Item.Item1</div>
                    @if (!string.IsNullOrEmpty(context.Item.Item2))
                    {
                        <div style="color:#BDBDBD" class="pl-2">@context.Item.Item2</div>
                    }
                </div>
            </ItemContent>
        </SAutoComplete>

        @if (ShowComparison)
        {
            <SAutoComplete Placeholder="@I18n.Apm("Search.Comparison")"
                           Label="@I18n.Apm("Search.Comparison")"
                           Clearable
                           BackgroundColor="white"
                           Items="listComparisons"
                           TItem="(ApmComparisonTypes value, string text)"
                           TValue="ApmComparisonTypes"
                           TItemValue="ApmComparisonTypes"
                           ItemText="item=>item.text"
                           ItemValue="item=>item.value"
                           ValueChanged="OnSelectChanged"
                           Value=Search.ComparisonType
                           Small
                           HideSelected=false
                           Class="rounded-2 mr-1"
                           Style="max-width:150px" />
        }

        <SDateTimeRangeToolbar Class="my-auto"
                               StartDateTime="@Search.Start.ToDateTimeOffset(CurrentTimeZone)"
                               EndDateTime="@Search.End.ToDateTimeOffset(CurrentTimeZone)"
                               OnUpdate="OnTimeUpdate"
                               OnAutoUpdate="OnTimeUpdate"
                               ShowQuickChange
                               ShowTimeZoneSelector
                               DefaultQuickRange="quickRangeKey"
                               ShowInterval />
        @if (ShowExceptError)
        {
            <MSwitch Value="Search.EnableExceptError" Label="白名单" Class="my-0 py-0 pl-4"
                     Color="info" ValueChanged="@((bool selected)=>EnableErrorExceptChange(selected))"
                     HideDetails="true"></MSwitch>
        }

    </div>
    @if (!IsService)
    {
        <div class="d-flex pt-2 mb-4">
            @if (IsEndpoint)
            {
                <SAutoComplete Placeholder="@I18n.Apm("Search.Endpoint")"
                               Label="@I18n.Apm("Search.Endpoint")"
                               Clearable
                               BackgroundColor="white"
                               Items="endpoints"
                               TItem="string"
                               TValue="string"
                               TItemValue="string"
                               ItemText="item=>item"
                               ItemValue="item=>item"
                               ValueChanged="OnEndpointChange"
                               Value=Search.Endpoint
                               Small
                               HideSelected=false
                               Class="rounded-2 mr-1"
                               Style="max-width:150px" />

                <SAutoComplete Placeholder="@I18n.Apm("Search.StatusCode")"
                               Label="@I18n.Apm("Search.StatusCode")"
                               Clearable
                               BackgroundColor="white"
                               Items="statuses"
                               TItem="string"
                               TValue="string"
                               TItemValue="string"
                               ItemText="item=>item"
                               ItemValue="item=>item"
                               ValueChanged="OnStatusCodeChange"
                               Value=Search.Status
                               Small
                               HideSelected=false
                               Class="rounded-2 mr-1"
                               Style="max-width:100px" />
            }

            else if (!IsService)
            {
                <SAutoComplete Placeholder="@I18n.Apm("Search.ExceptionType")"
                               Label="@I18n.Apm("Search.ExceptionType")"
                               Clearable
                               BackgroundColor="white"
                               Items="exceptions"
                               TItem="string"
                               TValue="string"
                               TItemValue="string"
                               ItemText="item=>item"
                               ItemValue="item=>item"
                               ValueChanged="OnExceptionChange"
                               Value=Search.ExceptionType
                               Small
                               HideSelected=false
                               Class="rounded-2 mr-1"
                               Style="max-width:200px" />
            }
            <SSelect Small @bind-Value="@Search.TextField"
                     Placeholder="@I18n.Apm("Search.SelectField")"
                     Label="@I18n.Apm("Search.SelectField")"
                     Items="@textFields"
                     ItemText="item => item"
                     ItemValue="item => item"
                     BackgroundColor="white"
                     HideDetails="@("auto")"
                     TItem="string"
                     TItemValue="string"
                     TValue="string"
                     Class="fill-card body2 mr-1"
                     Style="max-width:200px">
            </SSelect>
            <STextField Label="@I18n.Apm("Search.SearchValue")" Placeholder="@I18n.Apm("Search.SearchValue")" BackgroundColor="white" @bind-Value="@Search.TextValue" OnEnter="OnMessageEnter" Class="rounded-2" Style="width:100%" Small />
        </div>
    }
}